package edu.hawaii.duedates;


/**
 * The Library Class implements the ILibrary interface.  A valid library is comprised of a name, 
 * site url, password field, name field, and validity of the site.  The library may have additional
 * attributes such as a login form, links to a login page and/or summary page, and column names
 * for the table containing the book information.
 * 
 * @author Ronn Reeves and Robin E. Raqueno
 */
public class Library implements ILibrary {

  /** The library name. */
  private String name;
  /** The library url. */
  private String siteURL;
  /** The library password field. */
  private String passwordFieldName;
  /** The library user field. */
  private String userFieldName;
  /** The login link. */
  private String link;
  /** The login form name. */
  private String formName;
  /** The login error message. */
  private String errorMessage;
  /** The no borrowed items message. */
  private String noBorrowedItemsMessage;
  /** The title column name. */
  private String titleColumn;
  /** The date column name. */
  private String dateColumn;
  /** The library validity. */
  private boolean validity;
  /** The summary link. */
  private String summary;
  
  
  /**
   * Creates a library object with the given name, url, passwordField, userField, and a default 
   * validity of false.
   * 
   * @param name  The library's name.
   * @param url The library's url.
   * @param passwordField The password field of the library site.
   * @param userField The user field of the library site.
   */
  public Library(String name, String url, String passwordField, String userField) {
    this.name = name;
    this.siteURL = url;
    this.passwordFieldName = passwordField;
    this.userFieldName = userField;
    this.link = "";
    this.summary = "";
    this.formName = "";
    this.errorMessage = "";
    this.noBorrowedItemsMessage = "";
    this.validity = false;
  }
  
  
  /**
   * Set the name of this library.
   * 
   * @param name The name of the library.
   */
  public void setName(String name) {
    this.name = name;
  }
  /**
   * Returns the name of this library.
   * 
   * @return String The library name.
   */
  public String getName() {
    return this.name;
  }
  
  
  /**
   * Sets the site URL for this library's web site.
   *
   * @param url The web site url.
   */
  public void setSiteURL(String url) {
    this.siteURL = url;
  }
  /**
   * Returns the web site url for this library.
   * 
   * @return String The web site url.
   */
  public String getSiteURL() {
    return this.siteURL;
  }
  
  
  /**
   * Sets the password field of this library's web site.
   *
   * @param fieldName The password field.
   */
  public void setPasswordField(String fieldName) {
    this.passwordFieldName = fieldName;
  }
  /**
   * Returns the password field for this library's web site.
   * 
   * @return String The password field.
   */
  public String getPasswordField() {
    return this.passwordFieldName;
  }
  
  
  /**
   * Sets the userID field from this library's web site.
   *
   * @param fieldName The user id field. 
   */
  public void setUserIdField(String fieldName) {
    this.userFieldName = fieldName;
  }
  /**
   * Returns the user id field from this library's web site.
   * 
   * @return String The user id field.
   */
  public String getUserIdField() {
    return this.userFieldName;
  }

  
  /**
   * Sets the link to the login page of this library.
   * 
   * @param link The link to the login page.
   */
  public void setLoginLink(String link) {
    this.link = link;
  }
  /**
   * Returns the link to the login page of this library.
   * 
   * @return String The link of the login page.
   */
  public String getLoginLink() {
    return this.link;
  }

  
  /**
   * Sets the link to the summary page of this library.
   * 
   * @param link The link of the summary page.
   */
  public void setSummaryLink(String link) {
    this.summary = link;
  }
  /**
   * Returns the link to the summary page of this library.
   * 
   * @return String The link of the summary page.
   */
  public String getSummaryLink() {
    return this.summary;
  }
   

  /**
   * Sets the name of the form containing the login fields for this library.
   * 
   * @param formName The name of the form.
   */
  public void setFormName(String formName) {
    this.formName = formName;
  }
  /**
   * Returns the name of the form containing the login fields for this library.
   * 
   * @return String The name of the form.
   */
  public String getFormName() {
    return this.formName;
  }

  
  /**
   * Sets the error message displayed by the web site if login fails for this library.
   * 
   * @param message The error message displayed when login fails.
   */
  public void setLoginErrorMessage(String message) {
    this.errorMessage = message;
  }
  /**
   * Returns the error message displayed by the web site if login fails for this library.
   * 
   * @return String The error message displayed when login fails.
   */
  public String getLoginErrorMessage() {
    return this.errorMessage;
  }

  
  /**
   * Sets the message displayed by the web site if no items checked out for this library.
   *
   * @param message The message displayed when no items checked out.
   */
  public void setNoBorrowedItemsMessage(String message) {
    this.noBorrowedItemsMessage = message;
  }
  /**
   * Returns the message displayed by the web site if no items checked out for this library.
   * 
   * @return String The message displayed when no items checked out.
   */
  public String getNoBorrowedItemsMessage() {
    return this.noBorrowedItemsMessage;
  }

  
  /**
   * Sets the title column name of the table containing the checked out items.
   * 
   * @param columnName The column name of the table.
   */
  public void setTitleColumn(String columnName) {
    this.titleColumn = columnName;
  }
  /**
   * Returns the title column name of the table containing the checked out items.
   * 
   * @return String The column name of the table.
   */
  public String getTitleColumn() {
    return this.titleColumn;
  }

  
  /**
   * Sets the due date column name of the table containing the checked out items.
   * 
   * @param columnName The column name of the table.
   */
  public void setDateColumn(String columnName) {
    this.dateColumn = columnName;
  }
  /**
   * Returns the due date column name of the table containing the checked out items.
   * 
   * @return String The column name of the table.
   */
  public String getDateColumn() {
    return this.dateColumn;
  }

  
  /**
   * Sets the validity of this library info request.
   * 
   * @param validity  The validity status of this request.
   */
  public void setValid(boolean validity) {
    this.validity = validity;
  }
  /**
   * Returns true if the library site is valid.
   *
   * @return Boolean The validity of the library info request.
   */
  public boolean isValid() {
    return this.validity;
  }

  
  /**
   * Returns the library name and URL.
   *
   * @return String The name and URL of library.
   */
  public String toString() {
    return this.getName() + " (" + this.getSiteURL() + ")";
  }
}
